package com.tuju.jetpackfirstdemo.ui.complexform

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.LinearLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.tuju.jetpackfirstdemo.R
import com.tuju.jetpackfirstdemo.adapter.RecyclerAdapter
import com.tuju.jetpackfirstdemo.adapter.StringAdapter
import kotlinx.android.synthetic.main.activity_complex_form.*
import java.util.*
import kotlin.collections.ArrayList

class ComplexFormActivity : AppCompatActivity() {

    private var rowAdapter:StringAdapter? = null
    private var columnAdapter:StringAdapter? = null
    private var dataAdapter:RecyclerAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_complex_form)

        rowAdapter = StringAdapter()
        columnAdapter = StringAdapter()
        dataAdapter = RecyclerAdapter()

        rv_row.layoutManager = LinearLayoutManager(this@ComplexFormActivity, LinearLayout.HORIZONTAL,false)
        rv_row.adapter = rowAdapter

        rv_column.layoutManager = LinearLayoutManager(this@ComplexFormActivity)
        rv_column.adapter = columnAdapter

        val gridLayout = GridLayoutManager(this, 20)
        gridLayout.spanCount

        rv_data.layoutManager = LinearLayoutManager(this@ComplexFormActivity)
        rv_data.adapter = dataAdapter
        rv_data.setHasFixedSize(true)
        rv_data.isNestedScrollingEnabled = false

        initData()
    }


    private fun initData(){
        for (i in 0..20) {
            rowAdapter?.add("row$i")
        }
        for (i in 0..20) {
            columnAdapter?.add("column$i")
        }
        for (i in 0..20) {
            val lists = ArrayList<String>()
            for(j in 0..20){
                lists.add("{$i}data{$j}")
            }
            dataAdapter?.add(lists)
        }
        rowAdapter?.notifyDataSetChanged()
        columnAdapter?.notifyDataSetChanged()
        dataAdapter?.notifyDataSetChanged()
    }
}
